import type { IPublish } from '../interface/publish'
import type { IObserver } from '../interface/observer'

export default abstract class PublishAbstract implements IPublish {
  protected observerList: Array<IObserver> = []

  add(...observer: Array<IObserver>) {
    this.observerList.push(...observer)
  }

  remove(observer: IObserver) {
    const index = this.observerList.findIndex((item) => item === observer)
    if (index !== -1) {
      this.observerList.splice(index, 1)
    }
    return this
  }

  abstract notify(data: any): void

  abstract destory(): void
}
